;ClickNumber, a (cute?) hack AmiDos script to enter numbers with the mouse
;By Seumas McNally, Dark Unicorn Productions (longbow@mcd.on.ca)
;May be used freely as long as credit is given, if it's even worth using <g>
;Defaults, numbers out of the range of +- two hundred ten million
;(210,000,000) screw things up when they get multiplied by ten (explained
;later) and become more than +- two billion (out of signed long range)
;You could add some extra pre-multiplication checks and allow for a max of
;two billion, if you really needed numbers that high and didn't mind an
;even slower routine...
.def defnum 0
.def maxnum 210000000
.def minnum -210000000
;No repeated diskloading for the common commands
resident c:requestchoice
resident c:eval
;This sets them to "0" if they are not numbers
set cntot `eval [defnum] + 0`
set cnmax `eval [maxnum] + 0`
set cnmin `eval [minnum] + 0`
;Sets first message
set cnmsg "( starting )"
;Main loop
lab start
;The requestor, gadgets return 1 on far left going right, far right returns 0
set cnsel `requestchoice "enter a number: default [defnum], max [maxnum], min [minnum]" "$cnmsg number: { $cntot }" "0|1|2|3|4|5|6|7|8|9|+-|<-|clr|ok"`
set cnmsg "( .. )"
;If 0=OK was NOT selected, continue, else quit
if not $cnsel eq "0"
;If a number was selected (cnsel <=10, 0 returns 1, 1 returns 2...9 returns 10)
if not val $cnsel GT "10"
;Ads or subs (depends on total's sign) cnadd to cntot to add digit to end
;tot is *10 to give room for new digit, sel is -1 to get value of gadget
if val $cntot GE "0"
set cntot `eval ($cntot*10) + ($cnsel-1)`
skip minmax
; ^For speed, whatever it may actually gain
else
set cntot `eval ($cntot*10) - ($cnsel-1)`
skip minmax
endif
else
if val $cnsel eq "11"
;Switches around the sign of the total and sets msg
set cntot `eval $cntot - ($cntot * 2)`
set cnmsg "( negated )"
else
if val $cnsel eq "12"
;Divides the total by 10, these work on INTs so it chops last digit